package com.xysh.service;



import com.xysh.aes.AesKit;
import com.xysh.aes.EncryptKit;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;
@Service
public class CipherService {

    @Value("${case.apply.aesKey}")
    private String aesKey;

    @Value("${case.apply.sha256Key}")
    private String sha256Key;


    public String decrypt(String encryptContent, String sourceSignature) {
        String signature = EncryptKit.sha256Encrypt(encryptContent.concat(sha256Key));
        String content = AesKit.decryptAndDecodeToStr(encryptContent, aesKey);
        return content;
    }


    public Map<String,String> encrypt(String content) {
        String encodeStr = AesKit.encryptAndEncodeToStr(content, aesKey);
        String signature = EncryptKit.sha256Encrypt(encodeStr.concat(sha256Key));
        Map<String,String> map = new HashMap<>();
        map.put("encryptData",encodeStr);
        map.put("signature",signature);
        return map;
    }

    public static void main(String[] args) {
        CipherService cipherService = new CipherService();
        cipherService.aesKey="aesxysh123!QA123";
        cipherService.sha256Key="sha256xysh123";
        Map<String, String> encrypt = cipherService.encrypt("{\"status\":\"0000\",\"msg\":\"成功\"}");
        System.out.println(encrypt);
        System.out.println("解密后报文"+cipherService.decrypt(encrypt.get("encodeStr"),encrypt.get("signature")));

    }

}
